package Tree_09.ThreadedBinaryTree_03;

/*
 * @Author 罗
 * @date 2020/3/21 - 2:08 下午
 *
 */

import Tree_09.BinaryTree_01.DataStructure.Node;
import Tree_09.BinaryTree_01.Entity.HeroNode;


public class test {
    public static void main(String[] args) {
        ThreadedBinaryTree threadedBinaryTree = new ThreadedBinaryTree();
        threadedBinaryTree.addOrderly(new HeroNode(70, "罗"));
        threadedBinaryTree.addOrderly(new HeroNode(5, "你"));


        threadedBinaryTree.addOrderly(new HeroNode(10, "你"));
        threadedBinaryTree.addOrderly(new HeroNode(50, "罗"));
        threadedBinaryTree.addOrderly(new HeroNode(51, "你"));
        threadedBinaryTree.addOrderly(new HeroNode(200, "罗"));

        threadedBinaryTree.addOrderly(new HeroNode(2, "罗"));

        threadedBinaryTree.suffixList();


        suffixThreaded(threadedBinaryTree);
    }

    public static void suffixThreaded(ThreadedBinaryTree threadedBinaryTree) {
        System.out.println("后序线索化");
        threadedBinaryTree.threadedNodesSuffix();
        threadedBinaryTree.threadedListSuffix();
    }

    public static void prefixThreaded(ThreadedBinaryTree threadedBinaryTree) {
        System.out.println("前序线索化");
        threadedBinaryTree.threadNodesPreOrder();
        threadedBinaryTree.threadedListPreOrder();
    }


    public static void infixThreaded(ThreadedBinaryTree threadedBinaryTree) {
        System.out.println("中序线索化");
        threadedBinaryTree.threadedNodesInfix();
        System.out.println("遍历线中序索化二叉树");
        threadedBinaryTree.threadedList();
    }


    /**
     * 当继承的时候，子类的属性名和父类一致的时候，但类型又不同
     * 如果通过子类创建的对象指向了子类自己，则调用的是自己的属性（特指和父类重名的属性）
     * 如果强制转换为父类之后，再调用重名的属性，调用的就是父类的属性，显示为null
     * <p>
     * 属性名重复，若创建的对象指向的是子类，则调用子类的属性
     * 若创建的对象指向的是父类，则调用的是父类的属性
     * <p>
     * 若属性名只在父类中存在，默认调用父类的属性
     */
    public static void testExtends() {
        Node node = new ThreadedNode(new HeroNode(99, "测试"));
        node.left = new Node(new HeroNode(1100, "乌拉"));
        System.out.println(node.left.item);
        if (node instanceof ThreadedNode) {
            ThreadedNode threadedNode = (ThreadedNode) node;
            System.out.println("是实例，但是这里调用的是子类的left\t" + threadedNode.left);
        }

        System.out.println("----------------------------->");


        ThreadedNode threadedNode2 = new ThreadedNode(new HeroNode(12, "子类指向子类"));
        threadedNode2.left = new ThreadedNode(new HeroNode(12, "等下就不见了"));
        System.out.println(threadedNode2.item + "\n" + threadedNode2.left.item);


        if (threadedNode2 instanceof Node) {
            Node parent = (Node) threadedNode2;
            System.out.println("在父类中无法使用子类特有的属性");
            System.out.println(parent.item);
            System.out.println(parent.left);
        }
    }
}
